home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / MacSource / ArgvTrix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-14  |  3.9 KB  |  143 lines  |  [TEXT/CWIE]

  1. /*==============================================================================
  2. Project:    POV-Ray
  3.  
  4. Version:    3
  5.  
  6. File:    ArgvTrix.c
  7.  
  8. Description:
  9.     Faked Argv/argc handling routines.  This file maintains a simple simulation
  10.     of the Standard C argc/argv program command line parameters, letting an
  11.     "outer" Mac application build an argument list and pass it to "main()".
  12. ------------------------------------------------------------------------------
  13. Author:
  14.     Eduard [esp] Schwan
  15. ------------------------------------------------------------------------------
  16.     from Persistence of Vision(tm) Ray Tracer
  17.     Copyright 1996 Persistence of Vision Team
  18. ------------------------------------------------------------------------------
  19.     NOTICE: This source code file is provided so that users may experiment
  20.     with enhancements to POV-Ray and to port the software to platforms other 
  21.     than those supported by the POV-Ray Team.  There are strict rules under
  22.     which you are permitted to use this file.  The rules are in the file
  23.     named POVLEGAL.DOC which should be distributed with this file. If 
  24.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  25.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  26.     Forum.  The latest version of POV-Ray may be found there as well.
  27.  
  28.     This program is based on the popular DKB raytracer version 2.12.
  29.     DKBTrace was originally written by David K. Buck.
  30.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  31. ------------------------------------------------------------------------------
  32. Change History:
  33.     941221    [esp]    Created
  34. ==============================================================================*/
  35.  
  36. #define ARGVTRIX_C
  37.  
  38. /*==== my header =====*/
  39. #include "ArgvTrix.h"
  40.  
  41.  
  42. /*==== Macintosh-specific headers ====*/
  43. #include <errors.h>            /* dupFNErr, etc */
  44. #include <strings.h>        /* p2cstr */
  45. #include <Memory.h>            /* NewPtr*/
  46.  
  47.  
  48. /*==== Standard C headers ====*/
  49.  
  50. #include <string.h>        /* strcpy */
  51.  
  52.  
  53. /*==== General definitions ====*/
  54.  
  55. #define ARGV_MAX 100    /* maximum # of parameters in argv */
  56.  
  57.  
  58. /*==== Global variables (external scope) ====*/
  59.  
  60. int            my_argc = 0;
  61. char        **my_argv = NULL;
  62.  
  63.  
  64. /*==== Global variables (local scope) ====*/
  65.  
  66.  
  67. // ---------------------------------------------------------------------
  68. // InitArgv
  69. // Allocate memory for the fake argv parameter buffer
  70. // ---------------------------------------------------------------------
  71. void InitArgv(void)
  72. {
  73.     // If user forgot to dispose, do it now
  74.     if (my_argv)
  75.         DestroyArgv();
  76.     // Create an Argv array that can handle ARGV_MAX pointers
  77.     my_argv = (char**)NewPtr(ARGV_MAX * sizeof(char*));
  78.     // reset argc
  79.     my_argc = 0;
  80. } // InitArgs
  81.  
  82.  
  83. // ---------------------------------------------------------------------
  84. // DestroyArgv
  85. // All done with argc/argv, dispose storage
  86. // ---------------------------------------------------------------------
  87. void DestroyArgv(void)
  88. {
  89.     int    k;
  90.     // if array is allocated...
  91.     if (my_argv)
  92.         {
  93.         // destroy each argv string first, from argc on down
  94.         for (k=my_argc-1; k>=0; k--)
  95.             {
  96.             if (my_argv[k])
  97.                 {
  98.                 DisposePtr((Ptr)my_argv[k]);
  99.                 my_argv[k] = NULL;
  100.                 }
  101.             }
  102.         // destroy the argv array itself now
  103.         DisposePtr((Ptr)my_argv);
  104.         my_argv = NULL;
  105.         }
  106.     my_argc = 0;
  107. }
  108.  
  109.  
  110. // ---------------------------------------------------------------------
  111. // AddArg
  112. // Add "s" as the next parameter in the argv/argc list (copies it)
  113. // ---------------------------------------------------------------------
  114. void AddArg(char *s)
  115. {
  116.  
  117. #ifdef PROJECT_POVRAY
  118.     if ((**gPrefs2Use_h).progress >= eProgDebug)
  119.         printf("-d argv='%s', argc=%d, argcMax=%d\n",
  120.                 s, my_argc, ARGV_MAX);
  121. #endif
  122.  
  123.     if (my_argc < ARGV_MAX)
  124.     {
  125.         my_argv[my_argc] = (char*)NewPtr(strlen(s)+1);
  126.         if (my_argv[my_argc])
  127.             {
  128.             strcpy(my_argv[my_argc], s);
  129.             my_argc++;
  130.             }
  131.     }
  132.     else
  133.     {
  134. #ifdef PROJECT_POVRAY
  135.     if ((**gPrefs2Use_h).progress >= eProgDebug)
  136.         printf("## [AddArg.Error!] Argument overflow adding '%s'!  index=%d, max=%d\n",
  137.                 s, my_argc, ARGV_MAX);
  138. #endif
  139.     }
  140. } // AddArg
  141.  
  142.  
  143.